package com.soft.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.soft.entity.Employee;
import com.soft.mapper.EmployeeMapper; // 假设存在

import java.util.Map;
import java.util.HashMap;

@Service
public class EmployeeService {

    @Autowired
    private EmployeeMapper employeeMapper; // 假设存在

    /**
     * 注册员工
     * @param employeePassword
     * @param storeId
     * @return 生成的employeeId，如果失败返回null
     */
    public Long registerEmployee(String employeePassword, Long storeId) {
        Employee employee = new Employee();
        employee.setEmployeePassword(employeePassword); // 实际应加密存储，这里简化
        employee.setStoreId(storeId);
        int rows = employeeMapper.insert(employee);
        if (rows > 0) {
            return employee.getEmployeeId(); // 自增ID会在insert后可用
        }
        return null;
    }

    /**
     * 登录验证
     * @param employeeId
     * @param employeePassword
     * @return 是否成功
     */
    public boolean loginEmployee(Long employeeId, String employeePassword) {
        Employee employee = employeeMapper.selectById(employeeId);
        if (employee == null) {
            return false;
        }
        return employee.getEmployeePassword().equals(employeePassword); // 实际应比较加密密码
    }

    /**
     * 根据员工ID获取员工ID和门店ID
     * @param employeeId
     * @return Map with employeeId and storeId
     */
    public Map<String, Long> getEmployeeById(Long employeeId) {
        Employee employee = employeeMapper.selectById(employeeId);
        if (employee == null) {
            return null;
        }
        Map<String, Long> res = new HashMap<>();
        res.put("employeeId", employee.getEmployeeId());
        res.put("storeId", employee.getStoreId());
        return res;
    }
}